﻿using AppDesigner.DragDropEx;
using AppDesigner.iUIRender;
using AppDesigner.Model;
using AppDesigner.Shared;
using System.Windows;
using System.Windows.Controls;

namespace AppDesigner.ViewModel
{
    public class DrawViewModel : BindableViewModel, IDropTarget
    {

        #region Constructor

        public DrawViewModel()
        {

        }

        #endregion
      
        #region Properties

        public Panel LayoutPanel { get; set; }

        #endregion

        public void DragOver(DragDropInfo dragDropInfo)
        {
            
        }

        public void Drop(DragDropInfo dragDropInfo)
        {
            if (dragDropInfo.DragDropData is ControlNode)
            {
                ControlNode selecteControl = (ControlNode)dragDropInfo.DragDropData;
                string elementName = selecteControl.Name;
                BaseUIRender render = iMapper.ElementRenderMapper.Instance.GetMappingRender(elementName);
                render.Position = dragDropInfo.EndPosition;
                render.Size = LayoutPanel.RenderSize;
                render.Parent = LayoutPanel;
                render.ParentPanelType = PanelType.PCanvas;
                render.RenderToParent();
                render.RenderSelf();
            }
        }
    }
}
